﻿using SaaS.Model.Enums;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using XCore.Domain.Entities;
using XCore.Extensions;

namespace SaaS.Model.Entity.Blogs
{
    [Table("Blog_Articles")]
    public class Article : Entity<int>
    {
        /// <summary>
        /// 标题
        /// </summary>
        [StringLength(128)]
        [Required]
        public string Title { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        [Required]
        public string Content { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public ArticleStatus Status { get; set; }
        /// <summary>
        /// 浏览量
        /// </summary>
        public int Flow { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public short Sort { get; set; }

        /// <summary>
        /// 标记 ,号分隔
        /// </summary>
        public string TagString { get; set; }

        private string[] _tags;
        [NotMapped]
        public string[] Tags
        {
            get
            {
                if (_tags == null)
                    _tags = this.TagString.ToEnumerable<string>(",").ToArray();
                return _tags;
            }
            set
            {
                _tags = value;
            }
        }


        public int? CreatorUserId { get; set; }
        public DateTime CreationTime { get; set; }
    }
}
